﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using l1cs.server.model.Instance;
using l1cs.server.serverpackets;

namespace l1cs.server.model.gametime
{
    class L1GameTimeCarrier
    {
        private Timer _timer;
        private L1PcInstance _pc;

        public L1GameTimeCarrier( L1PcInstance pc )
        {
            _pc = pc;
        }

        public void run( object state )
        {
            if ( _pc.getNetConnection() == null )
            {
                _timer.Dispose();
                return;
            }

            int serverTime = (int)L1GameTimeClock.getInstance().currentTime().getSeconds();
            if ( serverTime % 300 == 0 )
            {
                _pc.sendPackets( new S_GameTime( serverTime ) );
            }
        }

        public void start()
        {
            //_timer.scheduleAtFixedRate( this, 0, 500 );
            _timer = new Timer( new TimerCallback( run ), null, 0, 500 );
        }

        public void stop()
        {
            _timer.Dispose();
        }
    }
}
